using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public struct ObjectPlacerPossibility {
	public float weight;
	public GameObject prefab;

	public ObjectPlacerPossibility(float weight,GameObject prefab) {
		this.weight=weight;
		this.prefab=prefab;
	}
}

public class RoomPrefabObjectPlacer:MonoBehaviour {
	private void Awake() {
		PlaceObject();
		Destroy(this);
	}

	[SerializeField] ObjectPlacerPossibility[] possibilities;

	private void PlaceObject() {
		float weightTotal = 0;
		foreach(var i in possibilities) weightTotal+=i.weight;

		float weightSelected = Random.Range(0,weightTotal);


		foreach(var i in possibilities) {
			weightSelected-=i.weight;
			if(weightSelected<0) {
				Instantiate(i.prefab,transform.position,Quaternion.identity,transform);
				break;
			}
		}
	}

}
